<template>
  <view class="case-container">
    <!-- 案例列表 -->
    <scroll-view scroll-y class="case-list">
      <view
        v-for="(item, index) in cases"
        :key="index"
        class="case-item"
        @click="handle2etail(item.CaseID)"
      >
        <text class="case-brief">{{ item.Title }}</text>
        <u-icon name="arrow-right" color="#999"></u-icon>
      </view>
    </scroll-view>
  </view>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import { getCaseApi } from './service'

interface CaseItem {
  title: string
  brief: string
  description: string
  reason: string
  preventionTips: string[]
}

@Component
export default class SecurityCases extends Vue {
  cases: any[] = []

  async getData() {
    const { records } = await getCaseApi({})
    this.cases = records
  }
  async onShow() {
    await this.getData()
  }
  handle2etail(CaseID: string) {
    uni.navigateTo({
      url: './detail?CaseID=' + CaseID
    })
  }
}
</script>

<style lang="scss" scoped>
.case-container {
  padding: 20rpx;
  height: 100vh;
  background-color: #f5f5f5;
}

.header {
  margin-bottom: 40rpx;
  .title {
    font-size: 36rpx;
    font-weight: bold;
    display: block;
  }
  .subtitle {
    font-size: 28rpx;
    color: #666;
  }
}

.case-list {
  height: calc(100vh - 200rpx);
}

.case-item {
  background-color: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
  border-radius: 32rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);

  .case-title {
    font-weight: bold;
    margin-right: 20rpx;
  }

  .case-brief {
    flex: 1;
    color: #333;
  }
}

.detail-container {
  padding: 40rpx;
  max-height: 70vh;

  .detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30rpx;

    .detail-title {
      font-size: 36rpx;
      font-weight: bold;
    }
  }

  .detail-content {
    max-height: 60vh;
  }

  .detail-text {
    display: block;
    margin-bottom: 30rpx;
    line-height: 1.6;
  }

  .warning-section,
  .prevention-section {
    margin-top: 40rpx;
    padding: 24rpx;
    background-color: #f8f8f8;
    border-radius: 12rpx;

    .warning-title,
    .prevention-title {
      font-weight: bold;
      display: block;
      margin-bottom: 16rpx;
    }
  }

  .tip-item {
    margin-top: 16rpx;
    padding-left: 20rpx;
  }
}
</style>
